public class SelectionSort<T extends Comparable<T>> {
    public T[] selectionSort(T[] data) {
        for (int i = 0; i < data.length; i++) {
            //假设第一个位置是最值（是最大值还是最小值，有Comparable接口实现决定），一般是最小值
            T m = data[i];
            //最值索引
            int mIndex = i;
            for (int j = i + 1 ; j < data.length; j++) {
                if (m.compareTo(data[j]) > 0){
                    m = data[j];
                    mIndex = j;
                }
            }
            T tem = data[i];
            data[i] = m;
            data[mIndex] = tem;
        }
        return data;
    }

    public static void main(String[] args) {
        Integer[] arr = {3, 2, 4, 1, 6};
        SelectionSort<Integer> selectionSort = new SelectionSort<>();
        selectionSort.selectionSort(arr);
        System.out.println();//打断点直接看结果
    }
}
